<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>商品劵结算管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" /></head>

<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox" id="tool">
		<div class="layui-inline">
			<label class="layui-input-inline">是否付款</label>
			<label class="layui-input-inline">
				<select name="countMoneyStatus" id="countMoneyStatus"></select>
			</label>
			<label class="layui-input-inline">姓名</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="memberName" placeholder="请输入姓名" />
			</label>
			<label class="layui-input-inline">手机号</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="memberPhone" placeholder="请输入手机号" />
			</label>
			<label class="layui-input-inline">卷标题</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="itemName" placeholder="请输入卷标题" />
			</label>

			<a class="layui-btn search_btn" lay-submit="" lay-filter="seacherBtn">搜索</a>
			<a class="layui-btn layui-btn-normal countMoneyBtn" >打款</a>
			<a class="layui-btn layui-btn-normal export_btn" >导出</a>
		</div>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>
</form>

<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">layui.use(['jquery', 'pageUtil', 'dialogUtil', 'table', 'dateUtil','fileUtil'],
    function() {
        var $ = layui.jquery,
			fileUtil = layui.fileUtil,
            dateUtil = layui.dateUtil,
            dialogUtil = layui.dialogUtil,
            table = layui.table,
            pageUtil = layui.pageUtil;
        var tableIns = null;
		pageUtil.initDict("shop_count_money_status",
            function(dictData) {
                pageUtil.showDict($("#countMoneyStatus"), pageUtil.aceeptDictContentList(dictData, "shop_count_money_status"), "请选择是否付款");

                var url = "/shopOrderCoupon/page?settleStatus=1";
                var cols = [{
                    type: 'checkbox',
                    fixed: 'left'
                },
                    {
                        type: 'numbers',
                        title: '序号'
                    },
                    {
                        field: 'memberName',
                        title: '姓名',
                        align: 'center'
                    },
                    {
                        field: 'memberPhone',
                        title: '手机号',
                        align: 'center'
                    },
                    {
                        field: 'itemName',
                        title: '商品名称',
                        align: 'center'
                    },
                    {field: 'image', title: '卷图片',align:'center', templet:function(d){
                            return "<img lay-event ='showPicture' src='"+d.image+"' style='width: 80px;height: 80px;'/>";
                        },width:100},
                    {field: 'image', title: '卷链接',align:'center', templet:function(d){
                            return "<input value='"+window.location.protocol+"//"+window.location.host+d.image+"' />";
                        },width:100},
                    {field: 'qrImage', title: '卷码',align:'center',width:180},
                    {
                        field: 'price',
                        title: '劵价格',
                        align: 'center'
                    },
                    {
                        field: 'brandName',
                        title: '品牌名称',
                        align: 'center'
                    },
                    {
                        field: 'catName',
                        title: '分类名称',
                        align: 'center'
                    },
                    {field: 'status', title: '交易状态',align:'center', templet:function(d){
						if (d.status == "1") {
							return "销售（未入库）";
						} else if (d.status == "5") {
							return "销售（已入库）";
						} else if (d.status == "2") {
							return "下架";
						} else if (d.status == "3") {
							return "结算";
						} else if (d.status == "4") {
							return "纠纷";
						}
					},width:100},
                    {field: 'issueStatus', title: '纠纷状态',align:'center', templet:function(d){
						if (d.issueStatus == "1") {
							return "无纠纷";
						} else if (d.issueStatus == "2") {
							return "纠纷中";
						} else if (d.issueStatus == "3") {
							return "申诉中";
						} else if (d.issueStatus == "4") {
							return "纠纷无效";
						} else if (d.issueStatus == "5") {
							return "纠纷有效";
						}
					},width:100},
                    {field: 'brandId', title: '是否付款',align:'center', templet:function(d){
                            return pageUtil.aceeptDictContentName(dictData,"shop_count_money_status",d.countMoneyStatus);
                        }},
                    {
                        field: 'uploadTime',
                        title: '上传时间',
                        width: 190,
                        align: 'center',
                        templet: function(d) {
                            return dateUtil.formatDate(new Date(d.createTime), "yyyy-MM-dd hh:mm:ss");
                        }
                    }];
                tableIns = pageUtil.initDate(cols, url, true);
            });

        // 导出
        $(".export_btn").on("click",function(){
            window.location.href = "/shopOrderCoupon/exportSettle?settleStatus=1";
        });

        $(".countMoneyBtn").click(function(){
            // 获取所有的ids
            var checkStatus = layui.table.checkStatus('entityList').data;

            if(checkStatus.length == 0){
                layer.alert("请选择至少一个商品卷！")
                return false;
            }

            var ids = [];
            $.each(checkStatus,function(i,v){
                ids.push(v.id);
            });
            var idsStr = ids.join(",");
            //console.log(ids.join(","));
            // 打款，并记录
            var index = layer.open({
                type: 1,
                title:'打款',
                area: ['400px', 'auto'], //宽高
                btn:['确定','取消'],
                content: '<div style="height: 195px;padding: 15px !important;">'+
                '<form class="layui-form" action="">'+
                '<div class="layui-form-item layui-form-text" >'+
                ' <textarea id="description" style="width:369px;height: 135px;!important;"></textarea>'+
                '</div>'+
                '</form>'+
                '</div>'
                ,success:function(){
                }
                ,yes:function (){
                    var description = $("#description").val();
                    if(description == null || description == ""){
                        dialogUtil.alert("请填写打款描述");
                        return false;
                    }
                    if(description.length > 200){
                        dialogUtil.alert("打款描述不能超过100个字");
                        return false;
                    }
                    var params={
                        "ids":idsStr,
                        "description":description
                    }
                    $.post("/shopOrderCoupon/createOrder", params, function (result) {
                        layer.close(index);
                        if (result.code === 0) {
                            //操作成功
                            // dialogUtil.alert(result.msg);
                            tableIns.reload();
                        } else {
                            //操作失败
                            dialogUtil.alert(result.msg);
                        }
                    }, "json");
                }
                ,btn2: function(index, layero){

                }
            });
        });

        table.on('tool(entityList)',
            function(obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if (layEvent === 'del') {
                    pageUtil.delete("确定删除该项吗？", "/shopOrderCoupon/delete", {
                            "id": data.id,
                            "_method": "DELETE"
                        },
                        function(data) {
                            tableIns.reload();
                        });
                }else if (layEvent === 'showPicture') {
					fileUtil.imageSingleShow(data.image);
				}
            });
    })</script>
</body>

</html>